<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" >
    <div class="layui-form-item">
        <label class="layui-form-label required">权限名称</label>
        <div class="layui-input-block">
            <input type="text" name="authorityName" lay-verify="required" lay-reqtext="不能为空" placeholder="请输入权限名称" value="" class="layui-input">
<!--            <tip>填写自己管理账号的名称。</tip>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限标识</label>
        <div class="layui-input-block">
            <input type="text" name="orderNumber" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="可用" checked="">
            <input type="radio" name="status" value="0" title="停用">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">类型</label>
        <div class="layui-input-inline">
            <select name="isMenu">
                <option value="">请选择类型</option>
                <option value=-1>菜单</option>
                <option value=0>目录</option>
                <option value=1>按钮</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">父级权限</label>
        <div class="layui-input-block">
            <input type="text" id="parentId" name="parentId"  lay-filter="tree" class="layui-input">

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">排序号</label>
        <div class="layui-input-block">
            <input type="number" name="orderNumber" lay-verify="required" lay-reqtext="不能为空" placeholder="请输入" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">菜单url</label>
        <div class="layui-input-block">
            <input type="text" name="menuUrl" lay-verify="required" lay-reqtext="不能为空" placeholder="请输入" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">属性</label>
        <div class="layui-input-inline">
            <select name="target">
                <option value="">请选择标签属性</option>
                <option value="_self">_self</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">菜单图标</label>
        <div class="layui-input-block">
            <input type="text" id="menuIcon"  name="menuIcon" lay-filter="iconPicker" class="hide">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form','treeSelect','layer','iconPickerFa','dataApi','common'], function () {
        var form = layui.form,
            treeSelect= layui.treeSelect,
            iconPickerFa = layui.iconPickerFa,
            common=layui.common,
            api = layui.dataApi,
            $ = layui.$;

        //菜单树
        treeSelect.render({
            // 选择器
            elem: '#parentId',
            // 数据
            data: api.menuTreelist,
            // 请求头
            headers: {},
            // 异步加载方式：get/post，默认get
            type: 'get',
            // 占位符
            placeholder: '修改默认提示信息',
            // 是否开启搜索功能：true/false，默认false
            search: true,
            // 一些可定制的样式
            style: {
                folder: {
                    enable: true
                },
                line: {
                    enable: true
                }
            },
            // 点击回调
            click: function(d){
                console.log(d);
            },
            // 加载完成后的回调函数
            success: function (d) {
                console.log(d);
              //选中节点，根据id筛选
                treeSelect.checkNode('tree', 3);

                console.log($('#tree').val());

               //获取zTree对象，可以调用zTree方法
                var treeObj = treeSelect.zTree('tree');
                console.log(treeObj);
                //刷新树结构
                treeSelect.refresh('tree');
            }
        });
        //图标
        iconPickerFa.render({
            // 选择器，推荐使用input
            elem: '#menuIcon',
            // fa 图标接口
            url: "../../lib/font-awesome-4.7.0/less/variables.less",
            // 是否开启搜索：true/false，默认true
            search: true,
            // 是否开启分页：true/false，默认true
            page: true,
            // 每页显示数量，默认12
            limit: 12,
            // 点击回调
            click: function (data) {
                console.log(data);
            },
            // 渲染成功后的回调
            success: function (d) {
                console.log(d);
            }
        });
        common.submitForm(api.menuAdd,form, "添加成功",null);

        // //监听提交
        // form.on('submit(saveBtn)', function (data) {
        //     var index = layer.alert(JSON.stringify(data.field), {
        //         title: '最终的提交信息'
        //     }, function () {
        //
        //         // 关闭弹出层
        //         layer.close(index);
        //
        //         var iframeIndex = parent.layer.getFrameIndex(window.name);
        //         parent.layer.close(iframeIndex);
        //
        //     });
        //
        //     return false;
        // });

    });
</script>
</body>
</html>
